//
//  BaseTableViewController.swift
//  SinaWeibo
//
//  Created by 林柱强 on 16/1/28.
//  Copyright © 2016年 林柱强. All rights reserved.
//

import UIKit

//协议中是必选的方法，不实现就会报错
class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {

    //添加用户是否登录标记
//    var userLogin = UserAccount.loadAccount() != nil
    var userLogin = UserAccount.userLogin()
    var visitorLoginView: VisitorLoginView?
    
    override func loadView() {
        userLogin ? super.loadView() : loadVisitorView()
    }
    
    private func loadVisitorView(){
        //view的大小  在 viewDidLoad就会设置
        visitorLoginView = VisitorLoginView()
        //设置代理
        visitorLoginView?.visitorDelegate = self
        view = visitorLoginView
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorWillRegister")
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorWillLogin")
    }
    
    //visitorDelegate 协议方法
    func visitorWillLogin() {
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func visitorWillRegister() {
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}